#!/usr/bin/perl -w
  
use strict;
use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use lib qw( /var/pwneth/htdocs/perlescent );
use Perlescent;

my $q = new CGI;

	my $p = $q->param('p');
	my $page = $q->param('page_id');
	my $comment = $q->param('c');

print $q->header;

my($post,$out);

my$tmpl = Perlescent->become('Theme');
my$cor = Perlescent->become('Core');

my$html = $tmpl->readTemplate('index');
	$out = $html;

if($p)
{
	$post = $cor->GetPostWithComments($p);
}
elsif($page)
{
	$post = $cor->GetPage($page);
}
elsif($comment)
{

}
else
{
	$post = $cor->GetRecentPosts;
}
		my $cats = $cor->CategoriesList;
		my $pgs = $cor->PagesList;
		my $rps = $cor->RecentPostsList;
		my $rcs = $cor->RecentCommentsList;

		$out =~ s/\$POSTS\$/$post/g;
		$out =~ s/\$PAGES_LIST\$/$pgs/g;
		$out =~ s/\$ERROR\$//g;
	$out =~ s/\$RECENT_POSTS\$/$rps/g;
	$out =~ s/\$RECENT_COMMENTS\$/$rcs/g;
	$out =~ s/\$CATEGORIES\$/$cats/g;

print $out;
